package com.codingInn.web.controller;

import com.codingInn.web.pojo.User;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

public class UserController extends AbstractController {
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

		//ModelAndView对象既能够绑定视图名字，又能够绑定数据(将数据存储到request域对象)
		User userA = new User();
		userA.setName("张三");
		userA.setAge(18);

		User userB = new User();
		userB.setName("张三");
		userB.setAge(18);

		List<User> userList = new ArrayList<>();
		userList.add(userA);
		userList.add(userB);

		ModelAndView mv = new ModelAndView();//数据模型和视图
		mv.addObject("users",userList);
		mv.setViewName("userlist");

		String myData = (String)getServletContext().getAttribute("myData");//可以在任意地方获得相应的参数

		return mv;
	}
}